home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gas_251.zip / bin_251 / bfd / irix-core.c < prev    next >
C/C++ Source or Header  |  1994-08-07  |  7KB  |  267 lines

  1. /* BFD back-end for Irix core files.
  2.    Copyright 1993, 1994 Free Software Foundation, Inc.
  3.    Written by Stu Grossman, Cygnus Support.
  4.    Converted to back-end form by Ian Lance Taylor, Cygnus Support
  5.  
  6. This file is part of BFD, the Binary File Descriptor library.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. /* This file can only be compiled on systems which use Irix style core
  23.    files (namely, Irix 4 and Irix 5, so far).  In the config/XXXXXX.mh
  24.    file for such a system add
  25.       HDEFINES=-DIRIX_CORE
  26.       HDEPFILES=irix-core.o
  27.    */
  28.  
  29. #include "bfd.h"
  30. #include "sysdep.h"
  31. #include "libbfd.h"
  32.  
  33. #ifdef IRIX_CORE
  34.  
  35. #include <core.out.h>
  36.  
  37. struct sgi_core_struct 
  38. {
  39.   int sig;
  40.   char cmd[CORE_NAMESIZE];
  41. };
  42.  
  43. #define core_hdr(bfd) ((bfd)->tdata.sgi_core_data)
  44. #define core_signal(bfd) (core_hdr(bfd)->sig)
  45. #define core_command(bfd) (core_hdr(bfd)->cmd)
  46.  
  47. static asection *
  48. make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
  49.      bfd *abfd;
  50.      CONST char *name;
  51.      flagword flags;
  52.      bfd_size_type _raw_size;
  53.      bfd_vma vma;
  54.      file_ptr filepos;
  55. {
  56.   asection *asect;
  57.  
  58.   asect = bfd_make_section_anyway (abfd, name);
  59.   if (!asect)
  60.     return NULL;
  61.  
  62.   asect->flags = flags;
  63.   asect->_raw_size = _raw_size;
  64.   asect->vma = vma;
  65.   asect->filepos = filepos;
  66.   asect->alignment_power = 4;
  67.  
  68.   return asect;
  69. }
  70.  
  71. static const bfd_target *
  72. irix_core_core_file_p (abfd)
  73.      bfd *abfd;
  74. {
  75.   int val;
  76.   int i;
  77.   char *secname;
  78.   struct coreout coreout;
  79.   struct idesc *idg, *idf, *ids;
  80.  
  81.   val = bfd_read ((PTR)&coreout, 1, sizeof coreout, abfd);
  82.   if (val != sizeof coreout)
  83.     {
  84.       if (bfd_get_error () != bfd_error_system_call)
  85.     bfd_set_error (bfd_error_wrong_format);
  86.       return 0;
  87.     }
  88.  
  89.   if (coreout.c_magic != CORE_MAGIC
  90.       || coreout.c_version != CORE_VERSION1)
  91.     return 0;
  92.  
  93.   core_hdr (abfd) = (struct sgi_core_struct *) bfd_zalloc (abfd, sizeof (struct sgi_core_struct));
  94.   if (!core_hdr (abfd))
  95.     return NULL;
  96.  
  97.   strncpy (core_command (abfd), coreout.c_name, CORE_NAMESIZE);
  98.   core_signal (abfd) = coreout.c_sigcause;
  99.  
  100.   if (bfd_seek (abfd, coreout.c_vmapoffset, SEEK_SET) != 0)
  101.     return NULL;
  102.  
  103.   for (i = 0; i < coreout.c_nvmap; i++)
  104.     {
  105.       struct vmap vmap;
  106.  
  107.       val = bfd_read ((PTR)&vmap, 1, sizeof vmap, abfd);
  108.       if (val != sizeof vmap)
  109.     break;
  110.  
  111.       switch (vmap.v_type)
  112.     {
  113.     case VDATA:
  114.       secname = ".data";
  115.       break;
  116.     case VSTACK:
  117.       secname = ".stack";
  118.       break;
  119. #ifdef VMAPFILE
  120.     case VMAPFILE:
  121.       secname = ".mapfile";
  122.       break;
  123. #endif
  124.     default:
  125.       continue;
  126.     }
  127.  
  128.       /* A file offset of zero means that the section is not contained
  129.      in the corefile.  */
  130.       if (vmap.v_offset == 0)
  131.     continue;
  132.  
  133.       if (!make_bfd_asection (abfd, secname,
  134.                   SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS,
  135.                   vmap.v_len,
  136.                   vmap.v_vaddr,
  137.                   vmap.v_offset,
  138.                   2))
  139.     return NULL;
  140.     }
  141.  
  142.   /* Make sure that the regs are contiguous within the core file. */
  143.  
  144.   idg = &coreout.c_idesc[I_GPREGS];
  145.   idf = &coreout.c_idesc[I_FPREGS];
  146.   ids = &coreout.c_idesc[I_SPECREGS];
  147.  
  148.   if (idg->i_offset + idg->i_len != idf->i_offset
  149.       || idf->i_offset + idf->i_len != ids->i_offset)
  150.     return 0;            /* Can't deal with non-contig regs */
  151.  
  152.   if (bfd_seek (abfd, idg->i_offset, SEEK_SET) != 0)
  153.     return NULL;
  154.  
  155.   make_bfd_asection (abfd, ".reg",
  156.              SEC_HAS_CONTENTS,
  157.              idg->i_len + idf->i_len + ids->i_len,
  158.              0,
  159.              idg->i_offset);
  160.  
  161.   /* OK, we believe you.  You're a core file (sure, sure).  */
  162.  
  163.   return abfd->xvec;
  164. }
  165.  
  166. static char *
  167. irix_core_core_file_failing_command (abfd)
  168.      bfd *abfd;
  169. {
  170.   return core_command (abfd);
  171. }
  172.  
  173. static int
  174. irix_core_core_file_failing_signal (abfd)
  175.      bfd *abfd;
  176. {
  177.   return core_signal (abfd);
  178. }
  179.  
  180. static boolean
  181. irix_core_core_file_matches_executable_p (core_bfd, exec_bfd)
  182.      bfd *core_bfd, *exec_bfd;
  183. {
  184.   return true;            /* XXX - FIXME */
  185. }
  186.  
  187. static asymbol *
  188. irix_core_make_empty_symbol (abfd)
  189.      bfd *abfd;
  190. {
  191.   asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
  192.   if (new)
  193.     new->the_bfd = abfd;
  194.   return new;
  195. }
  196.  
  197. #define irix_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
  198. #define irix_core_get_symtab _bfd_nosymbols_get_symtab
  199. #define irix_core_print_symbol _bfd_nosymbols_print_symbol
  200. #define irix_core_get_symbol_info _bfd_nosymbols_get_symbol_info
  201. #define irix_core_bfd_is_local_label _bfd_nosymbols_bfd_is_local_label
  202. #define irix_core_get_lineno _bfd_nosymbols_get_lineno
  203. #define irix_core_find_nearest_line _bfd_nosymbols_find_nearest_line
  204. #define irix_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
  205.  
  206. /* If somebody calls any byte-swapping routines, shoot them.  */
  207. void
  208. swap_abort()
  209. {
  210.   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
  211. }
  212. #define    NO_GET    ((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
  213. #define    NO_PUT    ((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
  214. #define    NO_SIGNED_GET \
  215.   ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
  216.  
  217. const bfd_target irix_core_vec =
  218.   {
  219.     "irix-core",
  220.     bfd_target_unknown_flavour,
  221.     true,            /* target byte order */
  222.     true,            /* target headers byte order */
  223.     (HAS_RELOC | EXEC_P |    /* object flags */
  224.      HAS_LINENO | HAS_DEBUG |
  225.      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
  226.     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  227.     0,                                               /* symbol prefix */
  228.     ' ',                           /* ar_pad_char */
  229.     16,                               /* ar_max_namelen */
  230.     3,                               /* minimum alignment power */
  231.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 64 bit data */
  232.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 32 bit data */
  233.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 16 bit data */
  234.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 64 bit hdrs */
  235.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 32 bit hdrs */
  236.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 16 bit hdrs */
  237.  
  238.     {                /* bfd_check_format */
  239.      _bfd_dummy_target,        /* unknown format */
  240.      _bfd_dummy_target,        /* object file */
  241.      _bfd_dummy_target,        /* archive */
  242.      irix_core_core_file_p    /* a core file */
  243.     },
  244.     {                /* bfd_set_format */
  245.      bfd_false, bfd_false,
  246.      bfd_false, bfd_false
  247.     },
  248.     {                /* bfd_write_contents */
  249.      bfd_false, bfd_false,
  250.      bfd_false, bfd_false
  251.     },
  252.     
  253.        BFD_JUMP_TABLE_GENERIC (_bfd_generic),
  254.        BFD_JUMP_TABLE_COPY (_bfd_generic),
  255.        BFD_JUMP_TABLE_CORE (irix_core),
  256.        BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
  257.        BFD_JUMP_TABLE_SYMBOLS (irix_core),
  258.        BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
  259.        BFD_JUMP_TABLE_WRITE (_bfd_generic),
  260.        BFD_JUMP_TABLE_LINK (_bfd_nolink),
  261.        BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  262.  
  263.     (PTR) 0            /* backend_data */
  264. };
  265.  
  266. #endif /* IRIX_CORE */
  267.